package com.weayer.service;

import com.weayer.dto.Car;
import com.weayer.dto.ResponseResult;
import com.weayer.remote.ServiceDriverClient;
import com.weayer.remote.ServiceMapClient;
import com.weayer.request.ApiDriverPointRequest;
import com.weayer.request.PointRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @description: Api服务 - 司机 - 轨迹点Service
 * @author: Weayer
 **/
@Service
public class PointService {
    @Autowired
    private ServiceDriverClient serviceDriverClient;
    @Autowired
    private ServiceMapClient serviceMapClient;

    /**
     * @Description: 上传轨迹点
     * @Param: [apiDriverPointRequest]
     * @return: com.weayer.dto.ResponseResult
     **/
    public ResponseResult upload(ApiDriverPointRequest apiDriverPointRequest){
        // 1. 获取carId，通过carId获取 tid、trid
        Long carId = apiDriverPointRequest.getCarId();
        Car car = serviceDriverClient.getCarById(carId).getData();
        String tid = car.getTid();
        String trid = car.getTrid();
        // 2. 上传轨迹点
        PointRequest pointRequest = new PointRequest();
        pointRequest.setTid(tid);
        pointRequest.setTrid(trid);
        pointRequest.setPoints(apiDriverPointRequest.getPoints());
        return serviceMapClient.upload(pointRequest);
    }
}
